import json


def sum_json_data(file_path):
    # 读取JSON文件
    with open(file_path, 'r') as file:
        data = json.load(file)

    # 检查数据结构是否符合预期
    if not isinstance(data, dict) or 'data' not in data or not isinstance(data['data'], list):
        print("JSON数据结构不符合预期")
        return

    # 初始化求和变量
    sums = {
        # 'ask': 0.0,
        # 'base_volume': 0.0,
        # 'bid': 0.0,
        # 'high': 0.0,
        # 'last_price': 0.0,
        # 'low': 0.0,
        # 'lowest_ask': 0.0,
        'target_volume': 0.0
    }

    # 遍历data数组中的每个对象
    for item in data['data']:
        # sums['base_volume'] += float(item['base_volume'])
        # sums['highest_price_24h'] += float(item['highest_price_24h'])
        # sums['last_price'] += float(item['last_price'])
        # # sums['lowest_ask'] += float(item['lowest_ask'])
        # sums['lowest_price_24h'] += float(item['lowest_price_24h'])
        sums['target_volume'] += float(item['target_volume'])

    # 打印结果
    print("各项数值字段的总和：")
    for key, value in sums.items():
        print(f"{key}: {value}")


if __name__ == '__main__':
    sum_json_data('result.json')

    # FIL/BTC
    print(808206230 / 2600)
    print(27919509154 / 106500)

    AA = {
      "ask": "0.0000230",
      "base_currency": "FIL",
      "base_volume": "377675.740000000000000000",
      "bid": "0.0000224",
      "high": "0.000024100000000000",
      "last_price": "0.0000230",
      "low": "0.000022400000000000",
      "target_currency": "BTC",
      "target_volume": "946039.790474333610000000",
      "ticker_id": "FIL_BTC"
    }

    # CRV
    print(80975474281 / 1687048.864843349980000000)

    # LTC
    print(80850320147 / 875866.120411235960000000)

    # DOGE
    print(76824646579 / 2122937.939681553990000000)


    # ETH/USDT
    print(36625273 / 36673464)

    # TRX/USDT
    print(34398423 / 35006550)

    # LTC/USDT
    print(28039030 / 27944437)
